package com.example.demo.controller;


import com.example.demo.mapper.mysqlMapper.myUserMapper;
import com.example.demo.pojo.mysqlPojo.myUser;
import com.example.demo.service.impl.redisServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/web")
@Api("swaggerDemoController相关的api")
public class MysqlController {
    @Autowired
    private myUserMapper mapper;

    @Autowired
    private redisServiceImpl redisservice;

    @RequestMapping("/insert")
    @ResponseBody
    public int add() throws ParseException {
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        myUser myuser=new myUser();
        myuser.setUsername("王五");
        myuser.setPassword("123123");
        myuser.setBirthday(sdf.parse("1977-11-22"));
        return mapper.insert(myuser);
    }

    @ApiOperation(value = "根据id查询用户信息", notes = "查询数据库中某个的用户信息")
    @ApiImplicitParam(name = "id", value = "用户ID", paramType = "path", required = true, dataType = "Integer")
    @RequestMapping("/findone")
    @ResponseBody
    public String SelectOne(String id){
        myUser u= redisservice.findById(id);
        return u==null?"找不到对象":u.getId()+"        "+u.getUsername();
    }
}
